var vue = new Vue({
				el: "body",
				data: {
					products: "",
					name: "",
					products1: "",
					haolist: "",
					mayuezongjia: 0,
					mayuenum: 0,
					type: false,
				},
				//创建成功后执行的函数
				created: function() {
					var APP_ID = '9etyUbhi95RBWTaoLBTyW5HP-gzGzoHsz';
					var APP_KEY = '6IkehXVEvUELlpo1SAf1c8PR';
					AV.init({
						appId: APP_ID,
						appKey: APP_KEY
					});
					var mthis = this;
					var query = new AV.Query('Business');
					query.find().then(function(products) {
						for(var i = 0; i < products.length; i++) {
							if(mthis.geturl() == products[i].id) {
								mthis.products = products[i].attributes.img[0];
								mthis.name = products[i].attributes.name;
							}
						}
						// 查询到商品后，在前端展示到相应的位置中。
					}).catch(function(error) {
						alert(JSON.stringify(123));
					});
					var query1 = new AV.Query('Commodity');
					query1.limit(parseInt(Math.random() * 10 + 5)); // 最多返回 10 条结果
					query1.skip(parseInt(Math.random() * 100)); // 跳过 20 条结果
					query1.find().then(function(products) {
						mthis.products1 = products;
						// 查询到商品后，在前端展示到相应的位置中。
					}).catch(function(error) {
						alert(JSON.stringify(123));
					});
					mthis.diaoyong();
				},
				methods: {
					geturl: function() {
						url = location.search;
						c_start = url.indexOf(name + "=")
						if(c_start != -1) {
							c_start = c_start + name.length + 1
							c_end = url.indexOf("&", c_start);
							if(c_end == -1) c_end = url.length;
							return unescape(url.substring(c_start, c_end));
						}
						return "";
					},
					wu_list: function() {
						location.href = "../Merchant-details/Merchant-details.html?index=" + this.geturl();
					},
					//飞入购物车的效果
					feiru: function() {
						var offset = $('#end').offset(),
							flyer = $(".inf1").clone();
						flyer.css({
							"width": "2rem",
							"border-radius": "2rem"
						});
						flyer.fly({
							start: {
								left: event.pageX,
								top: event.screenY - 80
							},
							end: {
								left: offset.left,
								top: offset.top,
								width: 0,
								height: 0,
							},
							onEnd: function() {
								flyer.remove();
							}
						});
					},
					fly: function(event, item) {
						vue.feiru();
						//点击加入购物车时将商品传到云端
						//这个this指向的是vue
						console.log($(this));
						//判断当前用户是否登录  如果为空就跳转到登录页面，如果不为空就去查询列表
						if(AV.User.current() == null) {
							location.href = "登录后.html";
						} else {
							var currentUser = AV.User.current().attributes.username;
							var query = new AV.Query('shopping');
							//按照时间顺序排序
							query.descending('createdAt');
							query.contains('cartname', item.attributes.name);
							query.find().then(function(products) {
								console.log("ssss");
								//购物车表有没有，没有创建，有更新
								if(products == "") {
									var Product = AV.Object.extend('shopping');
									var product = new Product();
									//设置商品名称
									product.set('cartname', item.attributes.name);
									//设置商品价格
									product.set('cartprice', item.attributes.price);
									//设置商品数量
									var cartnum = "1";
									product.set('cartnum', cartnum);
									product.set('owner', currentUser);
									product.save().then(function() {
										console.log("发布成功");
										vue.diaoyong();
									}, function(error) {
										console.log("添加失败");
										alert(JSON.stringify(error));
									});
								} else {
									console.log(products[0].attributes.cartnum);
									var cartnum = "1";
									var newcartnum = (cartnum * 1 + (products[0].attributes.cartnum) * 1);
									var todo = AV.Object.createWithoutData('shopping', '' + products[0].id + '');
									// 修改属性
									todo.set('cartnum', '' + newcartnum + '');
									// 保存到云端
									todo.save().then(function() {
										//  发布成功
										console.log("改数成功了");
										vue.diaoyong();
										//bug用户名必须为英文！！！否则url不转义会出错
										//location.href = "cart.html?User=" + zhuanyi(currentUser);
									}, function(error) {
										alert("添加失败");
										alert(JSON.stringify(error));
									});
								}
							vue.diaoyong();
							}, function(error) {
								// 异常处理
								console.log("失败");
							});
						}
					},
					diaoyong: function() {
						var query12 = new AV.Query("shopping");
						query12.find().then(function(product) {
							vue.haolist = product;
							var zongjian = 0;
							var wupengnum = 0;
							for(var i = 0; i < product.length; i++) {
								zongjian += parseFloat(product[i].attributes.cartprice)*parseInt(product[i].attributes.cartnum);
								wupengnum += parseInt(product[i].attributes.cartnum);
							}
							vue.mayuezongjia = zongjian.toFixed(2);
							vue.mayuenum = wupengnum;
						})
					},
					//清空数据库的函数
					clear: function() {
						var query12 = new AV.Query("shopping");
						query12.find().then(function(product) {
							for(var i = 0; i < product.length; i++) {
								var todo = AV.Object.createWithoutData('shopping', product[i].id);
								todo.destroy().then(function(success) {
									// 删除成功
									console.log("删除成功");
									vue.diaoyong();
								}, function(error) {
									// 删除失败
									console.log("删除失败");

								});
							}
						});
					},
					//点击减号的时候的函数
					reduce: function(t) {
						var query12 = new AV.Query("shopping");
						query12.find().then(function(product) {
							console.log(product[t]);
							if(product[t].attributes.cartnum > 1) {
								var cartnum = "1";
								var newcartnum = ((product[t].attributes.cartnum) * 1 - cartnum * 1);
								var todo = AV.Object.createWithoutData('shopping', '' +product[t].id+ '');
								// 修改属性
								todo.set('cartnum', '' + newcartnum + '');
								// 保存到云端
								todo.save().then(function() {
									console.log("改数成功了");
									vue.diaoyong();
								}, function(error) {
									alert("添加失败");
									alert(JSON.stringify(error));
								});
							} else {
                                var todo = AV.Object.createWithoutData('shopping', product[t].id);
								todo.destroy().then(function(success) {
									console.log("删除成功");
									vue.diaoyong();
								}, function(error) {
									console.log("删除失败");
								}); 
							}
						})
					},
					//点击加号的含函数
					add:function  (t) {
						var query12 = new AV.Query("shopping");
						query12.find().then(function(product) {
							console.log(product[t]);
								var cartnum = "1";
								var newcartnum = ((product[t].attributes.cartnum) * 1 + cartnum * 1);
								var todo = AV.Object.createWithoutData('shopping', '' +product[t].id+ '');
								// 修改属性
								todo.set('cartnum', '' + newcartnum + '');
								// 保存到云端
								todo.save().then(function() {
									//  发布成功
									console.log("改数成功了");
									vue.diaoyong();
								}, function(error) {
									alert("添加失败");
									alert(JSON.stringify(error));
								});
						})
					},
				},
			});
			function wu_alinck(t) {
//				location.href = "../../firm-order/firm-order.html?index="+t.getAttribute("id");
            location.href = "../../firm-order/firm-order.html";
			};